#include <func.h>
#include "threadPool.h"
#include "head.h"
int main(int argc,char *argv[]){
    //./server 172.22.123.229 1234 4
    ARGS_CHECK(argc,4);
    int workerNum = atoi(argv[3]);
    threadPool_t threadPool;
    threadPoolInit(&threadPool,workerNum);
    int sockFd;
    makeWorker(&threadPool);
    tcpInit(argv[1],argv[2],&sockFd);
    //开始epoll监听
    int epfd = epoll_create(10);
    epollAdd(sockFd,epfd);
    // epollAdd(exitPipe[0],epfd);
    struct epoll_event readyList[2];
    while (1)
    {
        int readyNum = epoll_wait(epfd,readyList,2,-1);
        puts("epoll ready");
        for(int i =0;i<readyNum;i++){
            if(readyList[i].data.fd == sockFd){
                int netFd = accept(sockFd,NULL,NULL);
                pthread_mutex_lock(&threadPool.mutex);
                enQueue(&threadPool.taskQueue,netFd);
                puts("new Task");
                pthread_cond_signal(&threadPool.cond);
                pthread_mutex_unlock(&threadPool.mutex);
            }
        }
    }
}